package com.example.administrator.szb.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.widget.TextView;

import com.example.administrator.szb.R;
import com.example.administrator.szb.activity.base.BasePresenter;
import com.example.administrator.szb.activity.base.MVPBaseFragmentActivity;
import com.example.administrator.szb.fragments.fragment_forXM.FragmentXM2;

import java.util.ArrayList;

public class MyXM2Activity extends MVPBaseFragmentActivity {
    private FragmentManager fragmentManager;
    private ArrayList<Fragment> fragmentArrayList;
    private FragmentXM2 fragment_wfcdxm, fragment_wsddxm;
    private FragmentTransaction fragmentTransaction;
    private Bundle bundle = new Bundle();
    private TextView textView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.comment_fragment);
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected void initView() {
        textView = findViewById(R.id.bar_title);
        textView.setText("我的项目");
        initFragment();//开启问题类型的切换

    }

    @Override
    protected void initEvent() {

    }

    @Override
    protected void initData() {

    }


    private void initFragment() {
        fragmentManager = getSupportFragmentManager();
        fragmentArrayList = new ArrayList<Fragment>();
        changeStatu(0);
    }
    /**
     * 根据点击问题的不同类型修改字体颜色
     *
     * @param i
     */
    private void changeStatu(int i) {
        fragmentTransaction = fragmentManager.beginTransaction();
        hideFragments(fragmentTransaction);
        switch (i) {
            case 0:
                if(fragment_wfcdxm == null){
                    fragment_wfcdxm = new FragmentXM2();
                    bundle.putInt("type",1);
                    fragment_wfcdxm.setArguments(bundle);
                    changeFragment(fragment_wfcdxm);
                }else {
                    fragmentTransaction.show(fragment_wfcdxm);
                }

                break;
            case 1:
                if(fragment_wsddxm == null){
                    fragment_wsddxm = new FragmentXM2();
                    bundle.putInt("type",2);
                    fragment_wsddxm.setArguments(bundle);
                    changeFragment(fragment_wsddxm);
                }else {
                    fragmentTransaction.show(fragment_wsddxm);
                }
                break;
        }

        fragmentTransaction.commit();
    }

    private void changeFragment(Fragment fragment) {
        fragmentArrayList.add(fragment);
        fragmentTransaction.add(R.id.frameLayout, fragment);
        fragmentTransaction.show(fragment);
    }

    private void hideFragments(FragmentTransaction fragmentTransaction) {
        for (Fragment fragment : fragmentArrayList) {
            fragmentTransaction.hide(fragment);
        }
    }
}
